<?php
require_once 'settings.php';

// if (!$con)
// {
// 	die('Could not connect: ' . mysql_error());
// }

// mysql_select_db("db_tursib", $con);



$sql_0="select id_station from t_stations";
$result_0 = mysql_query($sql_0);

while($row_0 = mysql_fetch_array($result_0)){
	$data_1 = "";
	$sql_1=" select  distinct(  bus_name)
	from t_stations as s 
	    inner join t_hours as h on s.id_station = h.t_stations_id_station
	    inner join t_busses as b on h.t_busses_id_bus = b.id_bus where s.id_station = '$row_0[0]'";
	
	
	$result_1 = mysql_query($sql_1);
	while($row_1 = mysql_fetch_array($result_1)){
	
		$data_1 .=   $row_1[0] ;
		$data_1 .= ",";
	
	}
	
	 
	if($data_1!= ""){
		$data_1  = substr($data_1, 0, -1);  
		$sql_2 ="UPDATE  t_stations  SET 
  			busses =  '$data_1'   WHERE id_station = '$row_0[0]'";
		$result_2 = mysql_query($sql_2);
		echo $result_2;
	
	}
	
	
	  
	
}



 
 



?>